<template>
    <div class="sh">
        <div class="sh-title">
            <div class="left">
                审核列表
            </div>
            <div class="right">
                共计 {{ total }} 项
            </div>
        </div>

        <div class="loading-box" v-if="loading">
            <van-loading color="#1989fa">
                加载中...
            </van-loading>
        </div>


        <div v-else>
            <div class="sh-list" v-if="tableList.length > 0">
                <div class="sh-item" v-for="(item, index) in tableList" :key="index">
                    <div class="sh-content">
                        <!-- 具体工作内容 -->
                        <div class="content-box">
                            <div class="label">具体工作内容：</div>
                            <div class="value">{{ item.workItem.workContent }}</div>
                        </div>
                        <div class="content-box">
                            <div class="label">上报人：</div>
                            <div class="value">{{ item.requestApplicationName }}</div>
                        </div>
                        <div class="content-box">
                            <div class="label">变更类型：</div>
                            <div class="value">{{ item.requestType }}</div>
                        </div>
                        <div class="content-box">
                            <div class="label">上报时间：</div>
                            <div class="value">{{ dayjs(item.approvalTime).format("YYYY-MM-DD HH:mm:ss") }}</div>
                        </div>
                    </div>
                    <div class="btn-group">
                        <div class="btn" style="color:#409eff" @click="goSh(item)">审核</div>
                    </div>
                </div>

            </div>
            <van-empty v-else description="暂无审核" />
            <div class="pagination-box" v-if="tableList.length > 0">
                <van-pagination v-model="params.pageNo" :total-items="total" :items-per-page="params.pageSize"
                    @change="getTableData" />
            </div>
        </div>

    </div>
</template>

<script setup>
import dayjs from "dayjs"
import { workApprovalPage } from "@/service/yearWork"
import { useUser } from "@/stores/user"
const userStore = useUser()
const router = useRouter()

let loading = ref(true)
let tableList = ref([])
let params = reactive({
    pageNo: 1,
    pageSize: 10,
    isDeleted: 0,
    approvalStatus: "待审批"
})
let total = ref(0)
function getTableData() {
    loading.value = true
    // 办公室的时候传3,科室长和分管领导就传approvalObjectId
    if (userStore.userInfo.userType == 'thirdLd') {
        params.approvalLevel = 3
    } else {
        params.approverObjectId = userStore.userInfo.userId
    }
    workApprovalPage(params).then(res => {
        if (res.code == 0) {
            tableList.value = res.data.records.map((item) => {
                item.workItem = JSON.parse(item.changeContentAfter)
                return item
            })
            total.value = res.data.total
            loading.value = false
        }
    })
}


function goSh(item) {
    router.push({
        path: '/sh/shDetails',
        query: {
            rowData: JSON.stringify(item)
        }
    })
}

onMounted(() => {
    getTableData()
})

</script>

<style lang="scss" scoped>
.sh {
    // display: flex;
    color: rgba(51, 51, 51, 1);
    padding: 0 26px;
    box-sizing: border-box;


    .sh-title {
        display: flex;
        align-items: center;
        justify-content: space-between;

        >div {
            font-size: 27px;
            font-weight: bold;
        }

    }

    .loading-box {
        display: flex;
        align-items: center;
        justify-content: center;
        height: calc(100vh - 92px - 10px - 140px - 120px);
    }

    .sh-list {
        overflow-y: scroll;
        height: calc(100vh - 92px - 10px - 140px - 120px);

        .sh-item {
            margin-bottom: 15px;
            padding: 20px 20px 0 20px;
            box-sizing: border-box;
            // min-height: 250px;
            border-radius: 20px;
            background: rgba(255, 255, 255, 1);
            box-shadow: 0px 4px 10px rgba(42, 130, 228, 0.1);

            .sh-content {
                font-size: 24px;

                .content-box {
                    margin-bottom: 10px;
                    display: flex;
                    align-items: center;

                    .label {
                        font-weight: bold;
                    }

                    .value {
                        width: 72%;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        white-space: nowrap;
                    }
                }
            }

            .btn-group {
                width: 100%;
                display: flex;
                justify-content: flex-end;
                padding-top: 5px;
                border-top: 1px solid rgba(225, 225, 225, 1);

                .btn {
                    text-align: center;
                    line-height: 65px;
                    color: rgba(166, 166, 166, 1);
                    flex: 1
                }

                .line {
                    width: 1px;
                    height: 60px;
                    background: rgba(225, 225, 225, 1)
                }
            }
        }
    }

    .pagination-box {
        margin-top: 20px;
    }
}
</style>